package com.day0915.Task;

import java.util.Scanner;

public class Order {
    Scanner in = new Scanner(System.in);

    String[] user_names ={"张清","张清",null,null};//订餐人姓名
    String[] dishNames = {"红烧带鱼","香菇炖鸡","土豆牛肉","鱼香肉丝"};//菜品
    double[] prices = {25,20,30,18.6};//价格
    int[] times = {12,18,0,0};//送餐时间
    String[] addresses = {"天成路207号","天成路207号",null,null};//送餐地址
    double[] sumMoney = {50,37.2,0,0};//总金额
    int[] states = {1,0,0,0};//订单状态    //1  已完成  0  已预定
    int[] fabulous = {0,0,0,0};//点赞数
    String[] dishMes = {"红烧带鱼 2份","鱼香肉丝 2份",null,null};

    //    1   我要订餐
    public void orderDish(){
        boolean isAdd = false;//是否可以订餐
        for(int i = 0; i < user_names.length; i++){
            if(user_names[i] == null){
                isAdd = true;
                System.out.print("请输入订餐人姓名：");
                String name = in.next();
                System.out.println("序号\t菜名\t\t单价\t点赞数");
                for(int j = 0; j < dishNames.length; j++){
                    System.out.println(j+1 + "\t\t" + dishNames[j] + "\t" + prices[j] + "元\t\t" + fabulous[j]);
                }
                System.out.print("请选择您需要的菜品编号：");
                int num = in.nextInt();//编号
                System.out.print("请输入您需要的份数：");
                int portion = in.nextInt();//数量
                System.out.print("请输入送餐时间（送餐时间是10点到20点整点送餐）：");
                int time = in.nextInt();
                if(time < 10 || time > 20){
                    System.out.println("您的输入有误，请重新输入（送餐时间是10点到20点整点送餐）：");
                    time = in.nextInt();
                }
                System.out.println("请输入送餐地址：");
                String address = in.next();
                //计算总价
                double sum = prices[num - 1] * portion;//菜品金额
                double meal_delivery_fee = sum >= 50 ? 0 : 5;//送餐费
                double sums = sum + meal_delivery_fee;//总金额
                System.out.println("订餐成功！");
                System.out.println("您订的是：" + dishNames[num - 1] + portion + "份");
                System.out.println("送餐时间：" + time + "点");
                System.out.println("餐费：" + sum + "元,送餐费：" + meal_delivery_fee + "元，总计：" + sums + "元。");
                //添加到各个数组中
                user_names[i] = name;
                times[i] = time;
                addresses[i] = address;
                sumMoney[i] = sum;
                dishMes[i] = dishNames[i] + " " + portion + "份";
                break;
            }
        }
        if (isAdd == false){
            System.out.println("对不起，您的餐袋已满！");
        }
    }

    //    2  查看餐袋
    public void viewMealBag(){
        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t\t总金额\t订单状态");
        for(int i = 0;i < user_names.length; i ++){
            if(user_names[i] != null){
                String state = (states[i] == 1) ? "已完成" : "已预定";
                System.out.println(i+1 + "\t\t" + user_names[i] + "\t" + dishMes[i] + "\t" + times[i] + "\t\t\t" + addresses[i] + "\t\t\t" + sumMoney[i] + "\t" + state);
            }
        }
    }

    //    3  签收订单
    public void signInOrder(){
        viewMealBag();
        System.out.print("请选择要签收的订单序号：");
        int order_no = in.nextInt();
        states[order_no - 1] = 1;
        System.out.println("订单已签收!");
    }

    //   4   删除订单
    public void deleteOrder(){
        viewMealBag();
        System.out.print("请输入要删除的订单序号：");
        int del_order = in.nextInt();
        if(states[del_order - 1] == 1){
            for(int i = del_order - 1; i < user_names.length - 1; i ++){
                user_names[i] = user_names[i + 1];
                dishMes[i] = dishMes[i + 1];
                times[i] = times[i + 1];
                addresses[i] = addresses[i + 1];
                sumMoney[i] = sumMoney[i + 1];
                states[i] = states[i + 1];
            }
            user_names[user_names.length - 1] = null;
            dishMes[dishMes.length - 1] = null;
            times[times.length - 1] = 0;
            addresses[addresses.length - 1] = null;
            sumMoney[sumMoney.length - 1] = 0;
            states[states.length - 1] = 0;
            System.out.println("订单删除成功！");
        }
        else {
            System.out.println("您选择的订单未完成，不可删除！");
        }
    }

    //   5   我要点赞
    public void giveTheThumbsUp(){
        System.out.println("序号\t菜名\t\t单价\t点赞数");
        for(int i = 0; i < dishNames.length; i++){
            System.out.println(i+1 + "\t\t" + dishNames[i] + "\t" + prices[i] + "元\t\t" + fabulous[i]);
        }
        System.out.print("请输入您要点赞的菜品序号：");
        int fab_num = in.nextInt();
        if(fab_num > dishNames.length ||fab_num < 0){
            System.out.print("输入错误，请重新输入您要点赞的菜品序号（1-" + dishNames.length + ")：");
            fab_num = in.nextInt();
        }
        fabulous[fab_num - 1] += 1;
        System.out.println("点赞成功！");
    }
}
